package main

import (
	"context"
	"fmt"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
)

func main() {
	hertz := server.New(server.WithHostPorts(":9993"))
	a := apiRouter{}
	hertz.Use(a.middleware())

	group := hertz.Group("api/", a.middleware())
	group.Any("/wechatpay", a.QQ())
	group.Any("/alipay", a.QQ())
	hertz.Run()
}

type apiRouter struct {
}

func (receiver apiRouter) QQ() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		fmt.Println(ctx.Request.URI())
		fmt.Println(ctx.Request.QueryString())
		fmt.Println(string(ctx.Request.Body()))
	}
}
func (receiver apiRouter) middleware() app.HandlerFunc {
	return func(c context.Context, ctx *app.RequestContext) {
		fmt.Println("======== start =========")
		fmt.Println(ctx.Request.Method(), ctx.ClientIP(), ctx.Request.URI())
		fmt.Println("======== end =========")
	}
}
